//
//  DYNavigationController.m
//  BaiSi
//
//  Created by mac on 16/10/14.
//  Copyright © 2016年 DeYi. All rights reserved.
//

#import "DYNavigationController.h"


@interface DYNavigationController ()<UIGestureRecognizerDelegate>

@end

@implementation DYNavigationController

+(void)load {
    //获取全局的属于 DYNavigationController 类型的所有 UINavigationBar
    UINavigationBar *bar = [UINavigationBar appearanceWhenContainedIn:self, nil];
    
    //设置字体颜色,大小
    NSMutableDictionary *attr = [NSMutableDictionary dictionary];
    attr[NSForegroundColorAttributeName] = [UIColor randomColor];
    attr[NSFontAttributeName] = [UIFont systemFontOfSize:25];
    [bar setTitleTextAttributes:attr];
    //背景图片
    [bar setBackgroundImage:[UIImage imageNamed:@"navigationbarBackgroundWhite"] forBarMetrics:UIBarMetricsDefault];
    
}

//<UIScreenEdgePanGestureRecognizer: 0x7f8912e9aaa0; state = Possible; delaysTouchesBegan = YES; view = <UILayoutContainerView 0x7f8912f1d350>; target= <(action=handleNavigationTransition:, target=<_UINavigationInteractiveTransition 0x7f8912e9a980>)>>

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
//     LHLog(@"%@",self.interactivePopGestureRecognizer.delegate);
    
    //全屏滑动返回
    UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self.interactivePopGestureRecognizer.delegate action:@selector(handleNavigationTransition:)];
    [self.view addGestureRecognizer:pan];
    pan.delegate = self;
    self.interactivePopGestureRecognizer.enabled = NO;
    
   
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


-(void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated {
    if (self.childViewControllers.count > 0) {//非根控制器,则添加返回按钮
        //自定义导航栏左边按钮
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        [button setImage:[UIImage imageNamed:@"navigationButtonReturn"] forState:UIControlStateNormal];
        [button setImage:[UIImage imageNamed:@"navigationButtonReturnClick"] forState:UIControlStateHighlighted];
        [button setTitle:@"返回" forState:UIControlStateNormal];
        [button setTitleColor:[UIColor redColor] forState:UIControlStateHighlighted];
        [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [button addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
        [button sizeToFit];
        button.imageEdgeInsets = UIEdgeInsetsMake(0, -20, 0, 0);
        UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithCustomView:button];
        viewController.navigationItem.leftBarButtonItem = item;
        
       //隐藏底部栏
        [viewController setHidesBottomBarWhenPushed:YES];
    }
    
    [super pushViewController:viewController animated:animated];
    
}

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
    return self.childViewControllers.count > 1;
}


#pragma mark 返回功能
- (void)back {
    LHLog(@"返回上一层");
    
    [self popViewControllerAnimated:YES];
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
